package com.geekstudy.reactor;

import com.geekstudy.reactive.streams.BusinessSubscriber;
import com.geekstudy.reactive.streams.SimplePublisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

import java.util.function.Supplier;

public class MonoDemo {

    static Logger logger = LoggerFactory.getLogger(MonoDemo.class);

    public static void main(String[] args) {
        demoMonoPublisher();
    }


    public static void demoMonoPublisher() {
        SimplePublisher publisher = new SimplePublisher();

        int totalSize = 5;
        // spring-webflux Mono
        Mono.from(publisher).subscribe(new BusinessSubscriber(totalSize));

        for(int size = 0; size < totalSize; size++) {
            publisher.publish("MonoDemo 2021 message " + size);
        }

        Supplier<String> supplier = () -> "Hello, World! ";
        Mono.fromSupplier(supplier).subscribe(data -> {
           System.out.println("MonoDemo [Thread : " + Thread.currentThread().getName() + " ] " +  data);
        });
    }
}
